import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'Home',
    component: () => import('@/views/Home.vue'),
    meta: {
      title: '首页 - 程序化启动方案校验系统'
    }
  },
  {
    path: '/device-template',
    name: 'DeviceTemplate',
    component: () => import('@/views/DeviceTemplate.vue'),
    meta: {
      title: '设备模板 - 程序化启动方案校验系统'
    }
  },
  {
    path: '/startup-plan',
    name: 'StartupPlan',
    component: () => import('@/views/StartupPlan.vue'),
    meta: {
      title: '启动方案 - 程序化启动方案校验系统'
    }
  },
  {
    path: '/terminology',
    name: 'Terminology',
    component: () => import('@/views/Terminology.vue'),
    meta: {
      title: '术语库 - 程序化启动方案校验系统'
    }
  }
  ,
  // 保留旧的路由以防兼容性问题
  {
    path: '/upload',
    name: 'Upload',
    component: () => import('@/views/Upload.vue'),
    meta: {
      title: '文档上传 - 程序化启动方案校验系统'
    }
  }
  // ,
  // {
  //   path: '/process',
  //   name: 'Process',
  //   component: () => import('@/views/Process.vue'),
  //   meta: {
  //     title: '处理中心 - 程序化启动方案校验系统'
  //   }
  // },
  // {
  //   path: '/results',
  //   name: 'Results',
  //   component: () => import('@/views/Results.vue'),
  //   meta: {
  //     title: '结果查看 - 程序化启动方案校验系统'
  //   }
  // }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫 - 设置页面标题
router.beforeEach((to, _from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title as string
  }
  next()
})

export default router
